package org.cytoscape.myapp.my_cyaction_app.internal;

import java.util.List;

import javax.swing.JOptionPane;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.model.CyNetworkManager;

public class CyFactoryNetworkAgregation {
	
	
	protected CyNetworkFactory networkFactory;
	protected CyApplicationManager appManager;
	protected CyNetworkManager networkManager;
	protected String attribute;
	private List<Object> valuesColumn;
	private CyRangeCompose rangos;
	
	public static int number = 0;

	
	
	public CyFactoryNetworkAgregation(CyNetworkFactory networkFactory,CyApplicationManager appManager,CyNetworkManager networkManager,String attribute){
		this.networkFactory = networkFactory;
		this.appManager = appManager;
		this.networkManager = networkManager;
		this.attribute = attribute;
		
		CyColumn columnas = appManager.getCurrentNetwork().getDefaultNodeTable().getColumn(attribute);
	
		this.valuesColumn = columnas.getValues(columnas.getType());
	
	}
	
	
	public CyNetwork CreateNetworkAgregation() {
		
		CyNetwork networkNew = this.networkFactory.createNetwork();
		networkNew.getRow(networkNew).set(CyNetwork.NAME, "NetworkTest"+String.valueOf(number));
		number++;
		
		getRangos().validar(this.getValuesColumn());
		
		for (String val : getRangos().GetRanksValidate()){
				networkNew.getRow(networkNew.addNode()).set(CyNetwork.NAME, String.valueOf(val));
		}
		
		networkManager.addNetwork(networkNew);
		return networkNew;
	}

	public CyRangeCompose getRangos() {
		return rangos;
	}
	
	public void setRangos(CyRangeCompose rangos) {
		this.rangos = rangos;
	}


	public List<Object> getValuesColumn() {
		return valuesColumn;
	}


	public void setValuesColumn(List<Object> valuesColumn) {
		this.valuesColumn = valuesColumn;
	}
}
